{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 输入一串字符，统计其中非英文字母的字符数量，并输出统计结果。不断重复上述过程，直到用户输入“over”为止\n",
    "ss = input()\n",
    "while ss != 'over':\n",
    "    n = len(ss)\n",
    "    for x in ss:\n",
    "        if x.isalpha() :   \n",
    "            n = n - 1\n",
    "    print('非英文字母的字符数量为:',n)\n",
    "    ss = input()\n",
    "\n",
    "# 可以用while True来代替while ss != 'over'，这样就可以一直循环，直到用户输入“over”为止\n",
    "while True:\n",
    "    ss = input()\n",
    "    if ss == 'over':\n",
    "        break\n",
    "    n = len(ss)\n",
    "    for x in ss:\n",
    "        if x.isalpha():\n",
    "            n = n - 1\n",
    "    print('非英文字母的字符数量为:', n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "153\n",
      "370\n",
      "371\n",
      "407\n"
     ]
    }
   ],
   "source": [
    "# 三位水仙花数计算\n",
    "for i in range(100, 1000):\n",
    "    a = i // 100 # 百位\n",
    "    b = (i % 100) // 10 # 十位\n",
    "    c = i % 10 # 个位\n",
    "    if a**3 + b**3 + c**3 == i:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 计算指定半径的圆的面积\n",
    "#请在这里定义getCircleArea函数，计算以r为半径的圆的面积，并返回\n",
    "import math\n",
    "n=int(input())\n",
    "\n",
    "def getCircleArea(r):\n",
    "    return math.pi * r * r\n",
    "\n",
    "for i in range(n):\n",
    "    r=float(input())\n",
    "    print('{:.2f}'.format(getCircleArea(r)))#调用getCircleArea并打印结果\n",
    "print('END.')\n",
    "\n",
    "#代码区结束"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 温度转换\n",
    "# 输入摄氏度用C开头，华氏度用F开头\n",
    "temperature = input()\n",
    "\n",
    "def convert(x):\n",
    "    if x[0] == 'C':\n",
    "        C = float(x[1: ])\n",
    "        F = C * 1.8 + 32\n",
    "        return f\"F{F:.2f}\"\n",
    "    elif x[0] == 'F':\n",
    "        F = float(x[1: ])\n",
    "        C = (F - 32) / 1.8\n",
    "        return f\"C{C:.2f}\"\n",
    "\n",
    "print(convert(temperature))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 求分数序列的和\n",
    "\n",
    "# 迭代\n",
    "up1 = 2\n",
    "up2 = 3\n",
    "down1 = 1\n",
    "down2 = 2\n",
    "\n",
    "def up(n):\n",
    "    if n == 1:\n",
    "        return up1\n",
    "    elif n == 2:\n",
    "        return up2\n",
    "    else:\n",
    "        return up(n - 1) + up(n - 2)\n",
    "\n",
    "def down(n):\n",
    "    if n == 1:\n",
    "        return down1\n",
    "    elif n == 2:\n",
    "        return down2\n",
    "    else:\n",
    "        return down(n - 1) + down(n - 2)\n",
    "\n",
    "def sum_frac(n):\n",
    "    if n <= 0:\n",
    "        return 0\n",
    "    elif n == 1:\n",
    "        return float(up1 / down1)\n",
    "    elif n == 2:\n",
    "        return float(up1 / down1 + up2 / down2)\n",
    "    else:\n",
    "        return float(up(n) / down(n) + sum_frac(n - 1))\n",
    "\n",
    "n = int(input())\n",
    "if sum_frac(n) == 0:\n",
    "    print(\"n输入错误\")\n",
    "else:\n",
    "    print(f\"前5项的累加和为{sum_frac(n):.2f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(0.1+0.2==0.3)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
